package com.framework.modules.base.controller;

import java.util.Arrays;
import java.util.Map;

import com.framework.common.validator.ValidatorUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.framework.modules.sys.entity.SysConfigEntity;
import com.framework.modules.sys.service.SysConfigService;
import com.framework.common.utils.PageUtils;
import com.framework.common.utils.R;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;


/**
 * 系统配置信息表
 *
 * @author MIT
 * @email litmiss@gmail.com
 * @date 2020-10-11 21:58:56
 */
@RestController
@RequestMapping("base/sysconfig")
@Api(tags = "SysConfigController")
public class SysConfigController {
    @Autowired
    private SysConfigService sysConfigService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @ApiOperation("list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = sysConfigService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @ApiOperation("info")
    public R info(@PathVariable("id") Long id) {
        SysConfigEntity sysConfig = sysConfigService.selectById(id);

        return R.ok().put("sysConfig", sysConfig);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @ApiOperation("save")
    public R save(@RequestBody SysConfigEntity sysConfig) {
        sysConfigService.insert(sysConfig);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @ApiOperation("update")
    public R update(@RequestBody SysConfigEntity sysConfig) {
        ValidatorUtils.validateEntity(sysConfig);
        sysConfigService.updateAllColumnById(sysConfig);//全部更新

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @ApiOperation("delete")
    public R delete(@RequestBody Long[] ids) {
        sysConfigService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

}
